﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Runtime.Serialization;
using Future.DataAccess;
using System.Data;

namespace Future.Contract
{
    [DataContract(Namespace = "http://azku.net")]
    [Serializable]
    public class BaseEntity : ICloneable
    {
        EntityState _state = EntityState.None;
        public BaseEntity() { }

        protected string _ConditionString;
        protected object _PK_VALUE;

        [DBColumnAttribue(false)]
        public virtual string PK
        {
            get { return ""; }
        }

        [DBColumnAttribue(false)]
        public virtual object PK_VALUE
        {
            get { return null; }
            set { _PK_VALUE = value; }
        }

        [DBColumnAttribue(false)]
        public virtual string TABLE_NAME
        {
            get;
            set;
        }

        [DBColumnAttribue(false)]
        public virtual string ConditionStatement
        {
            get { return _ConditionString; }
            set { _ConditionString = value; }
        }

        [DBColumnAttribue(false)]
        public virtual List<BaseEntity> ChildItem
        {
            get;
            set;
        }

        [DBColumnAttribue(false)]
        public virtual EntityState State
        {
            get { return _state; }
            set { _state = value; }
        }

        [DBColumnAttribue(false)]
        public virtual Type Child { get; set; }


        public void SetState()
        {
            switch (State)
            {
                case EntityState.None:
                    State = EntityState.Insert;
                    break;
                case EntityState.Select:
                    State = EntityState.Update;
                    break;
            }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
